
// 操作数据库的里面的表  

// Schema
// Schema主要用于定义MongoDB中集合Collection里文档document的结构,
// 理解为mongoose对表结构的定义   (不仅仅可以定义文档的结构和属性，还可以定义文档的实例方法、静态模型方法、复合索引等)
// 每个schema会映射到mongodb中的一个collection，schema不具备操作数据库的能力
// 定义Schema非常简单，指定字段名和类型即可，支持的类型包括以下8种

// String      字符串
// Number      数字    
// Date        日期
// Buffer      二进制
// Boolean     布尔值
// Mixed       混合类型
// ObjectId    对象ID    
// Array       数组

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const user_schema = new Schema({
  username: String,
  age: Number,
  pass: String,
  time: Date,
  word: String,
  msg: String,
  sex: String,
  birth: String
})

// Model   数据模型
// Model是由Schema编译而成的假想（fancy）构造器，具有抽象属性和行为
// Model的每一个实例（instance）就是一个document  document可以保存到数据库和对数据库进行操作
// model是由schema生成的模型，可以对数据库的操作  
// mongoose.model(`表名`, Schema) 

exports.user_model = mongoose.model("users", user_schema);    // users

// 如果表名称的最后一个字符是字母 会变成复数  user = users   city = cities  yyoh => yyohes 
// 如果表名称的最后一个字符是数字，则不变  user1  = user1 


const movie_schema = new Schema({
  "genres": Array,
  "casts": Array,
  "directors": Array,
  "rating": Object,
  "title": String,
  "collect_count": Number,
  "original_title": String,
  "subtype": String,
  "year": String,
  "images": Object,
  "alt": String,
  "id": String
})

exports.movie_model = mongoose.model('movies', movie_schema)



const qfuser_schema = new Schema({
  username: String,
  age: Number,
  password: String,
  email: String,
  phone: String,
  time: Date,
  word: String,
  msg: String,
  sex: String,
  birth: String,
  role: Number,  //1 普通用户 业主  //2. 保安  3. 物业  4. 管理员  5. 超级管理员  
  avatar: String
})

// exports.qfuser_schema = mongoose.model('qfusers',qfuser_schema)
exports.qfuser_model = mongoose.model("qfusers", qfuser_schema);

const qfanno_schema = new Schema({
  title: String,
  time: Date,
  context: String,
  type: Number,
  userInfo: Object

})

exports.qfanno_model = mongoose.model("qfanno1", qfanno_schema);


const comment_schema = new Schema({
  title: String,
  time: Date,
  context: String,
  type: Number,
  userInfo: Object,
  content: String
})

exports.comment_model = mongoose.model("comments", comment_schema);



const reactuser_schema = new Schema({
  username: String,
  password: String,
  phone: String,
  time: Date,
  role: Number,  //1 普通用户 业主  //2. 保安  3. 物业  4. 管理员  5. 超级管理员  
  avatar: String
})

exports.reactuser_model = mongoose.model("reactusers", reactuser_schema);


const reactanno_schema = new Schema({
  title: String,
  content: String,
  userInfo: Object,
  time: Date,
  type: Number,
  desc: String
})

exports.reactanno_model = mongoose.model("reactannos", reactanno_schema);

//收费项目
const shoufei_schema = new Schema({
  title: String,
  time: Date,
  context: String,
  type: Number,
  userInfo: Object,
  content: String,
  desc: String,
  remarks: String,
})

exports.shoufei_model = mongoose.model("shoufeis", shoufei_schema);

//维修
const weixiu_schema = new Schema({
  title: String,
  time: Date,
  context: String,
  type: Number,
  userInfo: Object,
  content: String,
  desc: String
})

exports.weixiu_model = mongoose.model("weixius", weixiu_schema);

// 添加招聘信息
const reactexecutive_schema = new Schema({
  title: String,
  username: String,
  phone: String,
  count: Number,
  time: Date,
  content: String,
  desc: String
})

exports.reactexecutive_model = mongoose.model("reactexecutives", reactexecutive_schema);

// 意见
const reactadvise_schema = new Schema({
  title: String,
  category: Array,
  content: String,
  userInfo: Object,
  time: Date,
  type: Number,
  desc: String
})

exports.reactadvise_model = mongoose.model("reactadvises", reactadvise_schema);  


// 装修表
const reactfinish_schema = new Schema({
  username:String,
  remark:String,
  phone:Number,
  time:Date,
  type:String,
  userInfo:Object,
  liked:Number,
  disliked:Number
})

exports.reactfinish_model = mongoose.model("reactfinishes",reactfinish_schema);  

